#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <mqueue.h>
#include <string.h>
using namespace std;

int main(int argc, char const *argv[])
{
    char* name = "/producer";
    struct mq_attr attr;
    attr.mq_curmsgs = 0;
    attr.mq_flags = 0;
    attr.mq_maxmsg = 10;
    attr.mq_msgsize = 100;
    mqd_t mqid = mq_open(name,O_RDWR | O_CREAT,0664,&attr);

    char* buffer = new char[1024];
    while(1){
        memset(buffer,0,1024);
        ssize_t size = mq_receive(mqid,buffer,1024,0);
        if(size > 0){
            cout << buffer << endl;
            if(buffer[0] == EOF){
                cout << "接收到了EOF,退出进程" << endl;
                break;
            }
        }
    }

    close(mqid);
    return 0;
}
